package cn.school.controller.publicPhone;


/**
 * 学生联系人
 */

import cn.school.common.api.CommonPage;
import cn.school.common.api.CommonResult;
import cn.school.publicPhone.service.FaceInfoServer;
import cn.school.publicPhone.vo.PhoneFaceSyncVO;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.ApiOperation;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/faceInfo")
public class FaceInfoController {

    @Resource
    private FaceInfoServer faceInfoServer;



    @PostMapping("/synchronous")
    @ApiOperation("同步话机的数据到我方")
    public CommonResult<Integer> synchronous() {
        String result = faceInfoServer.syncPhoneStudentsToFaceInfoServer();
        if (StringUtils.isEmpty(result)) {
            return CommonResult.success();
        }
        return CommonResult.failed(result);
    }


    @PostMapping("/pageList")
    @ApiOperation("pageList=>分页查询")
    public CommonResult<CommonPage<PhoneFaceSyncVO>> queryByPage(@RequestBody PhoneFaceSyncVO vo) {
        IPage<PhoneFaceSyncVO> pageList = faceInfoServer.getFaceList(vo);
        return CommonResult.success(CommonPage.restPage(pageList));
    }

    @PostMapping("/operationFaceSync")
    @ApiOperation("operationFaceSync=>同步照片")
    public CommonResult<Integer> operationFaceSync(@RequestBody PhoneFaceSyncVO vo) {
        String num = faceInfoServer.operationFaceSync(vo);
        if (StringUtils.isEmpty(num)) {
            return CommonResult.success();
        }
        return CommonResult.failed(num);
    }

    @PostMapping("/updateFaceSync")
    @ApiOperation("updateFaceSync=>同步照片")
    public CommonResult<Integer> updateFaceSync(@RequestBody PhoneFaceSyncVO vo) {
        String num = faceInfoServer.updateFaceSync(vo);
        if (StringUtils.isEmpty(num)) {
            return CommonResult.success();
        }
        return CommonResult.failed(num);
    }

    @PostMapping("/deleteFaceSync")
    @ApiOperation("deleteFaceSync=>删除同步照片")
    public CommonResult<Integer> deleteFaceSync(@RequestBody PhoneFaceSyncVO vo) {
        String num = faceInfoServer.deleteFaceInfo(vo);
        if (StringUtils.isEmpty(num)) {
            return CommonResult.success();
        }
        return CommonResult.failed(num);
    }

    @PostMapping("/batchCurdFaceSync")
    @ApiOperation("对FaceSync批量curd")
    public CommonResult<Integer> batchCurdFaceSync(@RequestBody List<PhoneFaceSyncVO> vos, String type) {
        String num = faceInfoServer.batchCurdFaceSync(vos, type);
        if (StringUtils.isEmpty(num)) {
            return CommonResult.success();
        }
        return CommonResult.failed(num);
    }


}
